<?php

/*
 * link	rev; charset; target;
 * a	rev; charset; shape; coords;
 * tag	shape; coords;
 * img	longdesc; name;
 * iframe	longdesc;
 * area	nohref;
 * head	profile;
 * html	version;
 * meta	scheme;
 * object	archive; classid; codebase; codetype; declare; standby
 * param	valuetype; type
 * td	axis; abbr;
 * th	scope
 */

include_once 'Answer_Patterns.php';
include_once 'Mount_DOM_tree.php';

class Refactoring_Old_Att_Remove extends Answer_Patterns {

   public function start($domDocument) {
      $result = "";
      $mount_tree = new Mount_DOM_tree();

      $allSearch = array($domDocument->getElementsByTagName('link'), $domDocument->getElementsByTagName('a'),
          $domDocument->getElementsByTagName('tag'), $domDocument->getElementsByTagName('img'),
          $domDocument->getElementsByTagName('iframe'), $domDocument->getElementsByTagName('area'), $domDocument->getElementsByTagName('head'),
          $domDocument->getElementsByTagName('html'), $domDocument->getElementsByTagName('meta'), $domDocument->getElementsByTagName('object'),
          $domDocument->getElementsByTagName('param'), $domDocument->getElementsByTagName('td'),
          $domDocument->getElementsByTagName('th'));

      foreach ($allSearch as $search) {
         foreach ($search as $f) {
            $answer = '';
            $flag = false;
            
            switch ($f->nodeName) {
               case "link":
                  if ($f->getAttribute("rev") || $f->getAttribute("charset") || $f->getAttribute("target")) {
                     $removeAtt = array("rev", "charset", "target");
                     $answer = '"rev", "charset", "target"';
                     $flag = true;
                  }
                  break;
               case "a":
                  if ($f->getAttribute("rev") || $f->getAttribute("charset") || $f->getAttribute("shape") || $f->getAttribute("coords")) {
                     $removeAtt = array("rev", "charset", "shape", "coords");
                     $answer = '"rev", "charset", "shape", "coords"';
                     $flag = true;
                  }
                  break;
               case "tag":
                  if ($f->getAttribute("shape") || $f->getAttribute("coords")) {
                     $removeAtt = array("shape", "coords");
                     $answer = '"shape", "coords"';
                     $flag = true;
                  }
                  break;
               case "img":
                  if ($f->getAttribute("longdesc") || $f->getAttribute("name")) {
                     $removeAtt = array("longdesc", "name");
                     $answer = '"longdesc", "name"';
                     $flag = true;
                  }
                  break;
               case "iframe":
                  if ($f->getAttribute("longdesc")) {
                     $removeAtt = array("longdesc");
                     $answer = '"longdesc"';
                     $flag = true;
                  }
                  break;
               case "area":
                  if ($f->getAttribute("nohref")) {
                     $removeAtt = array("nohref");
                     $answer = '"nohref"';
                     $flag = true;
                  }
                  break;
               case "head":
                  if ($f->getAttribute("profile")) {
                     $removeAtt = array("profile");
                     $answer = '"profile"';
                     $flag = true;
                  }
                  break;
               case "html":
                  if ($f->getAttribute("version")) {
                     $removeAtt = array("version");
                     $answer = '"version"';
                     $flag = true;
                  }
                  break;
               case "meta":
                  if ($f->getAttribute("scheme")) {
                     $removeAtt = array("scheme");
                     $answer = '"scheme"';
                     $flag = true;
                  }
                  break;
               case "object":
                  if ($f->getAttribute("archive") || $f->getAttribute("classid") ||
                      $f->getAttribute("codebase") || $f->getAttribute("codetype") || 
                      $f->getAttribute("declare") || $f->getAttribute("standby")) {
                     $removeAtt = array("archive", "classid", "codebase", "codetype", "declare", "standby");
                     $answer = '"archive", "classid", "codebase", "codetype", "declare", "standby"';
                     $flag = true;
                  }
                  break;
               case "param":
                  if ($f->getAttribute("valuetype") ||  $f->getAttribute("type")) {
                     $removeAtt = array("valuetype", "type");
                     $answer = '"valuetype", "type"';
                     $flag = true;
                  }
                  break;
               case "td":
                  if ($f->getAttribute("axis") ||  $f->getAttribute("abbr")) {
                     $removeAtt = array("axis", "abbr");
                     $answer = '"axis", "abbr"';
                     $flag = true;
                  }
                  break;
               case "th":
                  if ($f->getAttribute("axis") ||  $f->getAttribute("abbr") ||
                      $f->getAttribute("scope")) {
                     $removeAtt = array("axis", "abbr", "scope");
                     $answer = '"axis", "abbr", "scope"';
                     $flag = true;
                  }
                  break;
            }

            if ($flag) {
               $result .= parent::elementAnswerPatterns("&LT;$f->nodeName&GT;", $f->getLineNo(), $answer, "Atributo(s) que deve(m) ser removido(s): ", " e contém atributos que não são mais utilizados");
               $result .= parent::tableAnswer($mount_tree->structHTML($f, 1, 0), $mount_tree->structHTMLElementRefactory($f, 1, 0, "$f->nodeName", 1, "", $removeAtt));
            }
         }
      }

      if (!empty($result)) {
         $result = parent::titleAnswerPatterns("Remover atributos que foram descontinuados porque causam impacto negativo na compatibilidade dos user-agent") . $result;
      }
      return $result;
   }

}

?>
